//
//  PieView.swift
//  SwiftUIShape
//
//  Created by 李煜 on 2024/7/31.
//

import SwiftUI
//圆饼图
struct PieView: View {
	var body: some View {
		ZStack {
			Path { path in
				path.move(to: CGPoint(x: 187, y: 187))
				path.addArc(center: .init(x: 187, y: 187), radius: 150, startAngle: .degrees(0), endAngle: .degrees(190), clockwise: true)
			}
			.fill(.yellow)
			
			Path { path in
				path.move(to: CGPoint(x: 187, y: 187))
				path.addArc(center: .init(x: 187, y: 187), radius: 150, startAngle: .degrees(190), endAngle: .degrees(110), clockwise: true)
			}
			.fill(.teal)
			
			Path { path in
				path.move(to: CGPoint(x: 187, y: 187))
				path.addArc(center: .init(x: 187, y: 187), radius: 150, startAngle: .degrees(110), endAngle: .degrees(90), clockwise: true)
			}
			.fill(.blue)
			
			Path { path in
				path.move(to: CGPoint(x: 187, y: 187))
				path.addArc(center: .init(x: 187, y: 187), radius: 150, startAngle: .degrees(90), endAngle: .degrees(0), clockwise: true)
			}
			.fill(.purple)
			// 使用offset偏移来突出紫色扇形
			.offset(x: 20, y: 20)
			//或者叠加一个边框突出紫色
			.overlay{
				Text("25%")
					.font(.system(.largeTitle, design: .rounded))
					.bold()
					.foregroundStyle(.white)
					.offset(x: 80, y: -110)
			}
		}
	}
}

#Preview {
	PieView()
}
